/*
 * Copyright Iain Sproat, 2009
 * 
 *
 */
using System;
using Newtonsoft.Json;

namespace FreeBase.Domain
{
	/// <summary>
	/// Description of FBText.
	/// </summary>
	[JsonObject(MemberSerialization.OptIn)]
	public class FBText : FBValueType<string>
	{
		public FBText()
		{
		}
		public FBText(string val )
		{
			this.Value = val;
		}
		
		[JsonProperty("lang")]
		public FBLang Language{ get; set; }
		
		public override string Value{ get; set; }
		
		public static implicit operator FBText( string text )
		{
			FBText t = new FBText( text );
			t.Language = "/lang/en";
			return t;
		}
		
		public override bool Equals(object obj)
		{
			if( obj == null )
				return false;
			FBText t = obj as FBText;
			if( t == null )
			{
				string s = obj as string;
				if( s == null )
					return false;
				return s == this.Value;
			}
			return t.Value == this.Value
				&& t.Language == this.Language
				&& t.Type == this.Type;
		}
		
		public static bool operator ==(FBText lhs, object rhs)
		{
			return lhs.Equals( rhs );
		}
		public static bool operator !=(FBText lhs, object rhs)
		{
			return !lhs.Equals( rhs );
		}
		
		public override int GetHashCode()
		{
			return this.Language.GetHashCode()
				* this.Type.GetHashCode()
				* this.Value.GetHashCode();
		}
		
		public override string ToString()
		{
			return this.Value;
		}
		

	}
}
